package com.lanhao.aot.pdfmerge;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

import org.apache.commons.collections.CollectionUtils;

import cn.hutool.core.img.ImgUtil;

public class ImageMergeDemo {
	public static void main(String[] args) {
		doRussianPostLabelMerge();
//		doCDEKLabelMerge();
	}

	public static void doRussianPostLabelMerge() {
		String labelName = "D:/RussianPost_80107577120011.png";
		try {
			BufferedImage image = PDF2ImageUtil.pdf2Image(new File("D:/RussianPost_80107577120011.pdf"), null);
			File cutFile = new File("D:/RussianPost_80107577120011_cut.png");
			ImgUtil.cut(image, cutFile, new Rectangle(0, 0, 1180, 835));
			List<BufferedImage> imageList = new ArrayList<BufferedImage>();
			imageList.add(ImageIO.read(cutFile));
			imageList.add(PDF2ImageUtil.ruTemplateImage);
			
			PDF2ImageUtil.mergeImagetogeter(new File(labelName), imageList, "PNG", "0");
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void doCDEKLabelMerge() {
		// 处理合并的逻辑
		List<BufferedImage> imageList = PDF2ImageUtil.pdf2BufferedImageList(new File("D:/CDEK_1328259212.pdf"));
		if (CollectionUtils.isNotEmpty(imageList)) {
			try {
				imageList.add(PDF2ImageUtil.cdekTemplateImage);
				PDF2ImageUtil.mergeImagetogeter(new File("D:/CDEK_1328259212_Merge.png"), imageList, "PNG", "0");
				// 将多张图合并为一张图
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
